import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    // {
    //   path: '/',
    //   name: 'home',
    //   component: HomeView,
    // },
    {
      //登录
      path: "/",
      name: "Login",
      component: () => import("../views/Login.vue"),
    },

    {
      //主页面
      path: "/MainView",
      name: "MainView",
      component: () => import("../views/MainView.vue"),
      meta: { requiresAuth: true },
      children: [
        {
          //日志表
          path: "/UserActionLog",
          name: "UserActionLog",
          component: () => import("../views/UserActionLog.vue"),
        },
        {
          //添加角色
          path: "/RBAC/AddRoleDataHtml",
          name: "AddRoleDataHtml",
          component: () => import("../views/RBAC/AddRoleDataHtml.vue"),
        },
        {
          //添加用户
          path: "/RBAC/AddUserDataHtml",
          name: "AddUserDataHtml",
          component: () => import("../views/RBAC/AddUserDataHtml.vue"),
        },
        {
          //添加权限
          path: "/RBAC/AddPremissionDataHtml",
          name: "AddPremissionDataHtml",
          component: () => import("../views/RBAC/AddPremissionDataHtml.vue"),
        },
        //#region 工序管理
        {
          //工序添加
          path: "/AddProcessData",
          name: "AddProcessData",
          component: () => import("../views/Process/AddProcessData.vue"),
        },
        {
          //工序显示
          path: "/ShowProcessData",
          name: "/ShowProcessData",
          component: () => import("../views/Process/ShowProcessData.vue"),
        },
        //#endregion
        //#region 仓库管理
        {
          //添加仓库
          path: "/AddWarehouse",
          name: "AddWarehouse",
          component: () => import("../views/Warehouse/AddWarehouse.vue"),
        },
        {
          //显示仓库
          path: "/ShowWarehouse",
          name: "ShowWarehouse",
          component: () => import("../views/Warehouse/ShowWarehouse.vue"),
        },
        {
          //修改仓库
          path: "/UpWarehouse",
          name: "UpWarehouse",
          component: () => import("../views/Warehouse/UpWarehouse.vue"),
        },
        {
          //仓库明细
          path: "/WarehouseDetail",
          name: "WarehouseDetail",
          component: () => import("../views/Warehouse/WarehouseDetail.vue"),
        },
        {
          //仓库汇总
          path: "/WarehouseGather",
          name: "WarehouseGather",
          component: () => import("../views/Warehouse/WarehouseGather.vue"),
        },
        //#endregion
        {
          //企业管理显示
          path: "/Basics/EnterpriseQuery",
          name: "EnterpriseQuery",
          component: () => import("../views/Basics/EnterpriseQueryView.vue"),
        },
        {
          //部门管理显示
          path: "/Basics/DepartmentQuery",
          name: "DepartmentQuery",
          component: () => import("../views/Basics/DepartmentQueryView.vue"),
        },
        {
          //工艺路线添加
          path: "/ProducManagement/ProcessRouteAdd",
          name: "ProcessRouteAdd",
          component: () =>
            import("../views/ProducManagement/ProcessRouteAddView.vue"),
        },
        {
          //工艺路线显示
          path: "/ProducManagement/ProcessRouteQuery",
          name: "ProcessRouteQuery",
          component: () =>
            import("../views/ProducManagement/ProcessRouteQueryView.vue"),
        },
        //资源管理显示
        {
          path: "/ResourceShow",
          name: "ResourceShow",
          component: () => import("../views/Fabricate/ResourceShow.vue"),
        },
        //资源添加
        {
          path: "/ResourceAdd",
          name: "ResourceAdd",
          component: () => import("../views/Fabricate/ResourceAdd.vue"),
        },
        //资源修改
        {
          path: "/ResourceUpdate",
          name: "ResourceUpdate",
          component: () => import("../views/Fabricate/ResourceUpdate.vue"),
        },
        //客户列表
        {
          //物料管理显示
          path: "/MaterialManagement/MaterialManagementList",
          name: "MaterialManagementList",
          component: () =>
            import("../views/MaterialManagement/MaterialManagementList.vue"),
        },
        {
          //物料管理添加
          path: "/MaterialManagement/MaterialManagementAdd",
          name: "MaterialManagementAdd",
          component: () =>
            import("../views/MaterialManagement/MaterialManagementAdd.vue"),
        },
        {
          //物料清单显示
          path: "/BillMaterials/BillMaterialsList",
          name: "BillMaterialsList",
          component: () =>
            import("../views/BillMaterials/BillMaterialsList.vue"),
        },
        {
          //物料清单添加
          path: "/BillMaterials/BillMaterialsAdd",
          name: "BillMaterialsAdd",
          component: () =>
            import("../views/BillMaterials/BillMaterialsAdd.vue"),
        },
        {
          //主生产计划添加
          path: "/AddMainPlans",
          name: "AddMainPlans",
          component: () => import("../views/MainPlans/AddMainPlans.vue"),
        },
        {
          //主生产计划显示
          path: "/ShowMainPlans",
          name: "ShowMainPlans",
          component: () => import("../views/MainPlans/ShowMainPlans.vue"),
        },
        {
          //主生产计划修改
          path: "/UpMainPlan",
          name: "UpMainPlan",
          component: () => import("../views/MainPlans/UpMainPlan.vue"),
        },
        {
          path: "/CustomerShow",
          name: "CustomerShow",
          component: () => import("../views/Customers/CustomerShow.vue"),
        },
        //客户添加
        {
          path: "/CustomerAdd",
          name: "CustomerAdd",
          component: () => import("../views/Customers/CustomerAdd.vue"),
        },
        //客户信息修改
        {
          path: "/CustomersUpdate",
          name: "CustomersUpdate",
          component: () => import("../views/Customers/CustomersUpdate.vue"),
        },
        //销售订单列表
        {
          path: "/OrdersShow",
          name: "OrdersShow",
          component: () => import("../views/Orders/OrdersShow.vue"),
        },
        //销售订单添加
        {
          path: "/OrdersAdd",
          name: "OrdersAdd",
          component: () => import("../views/Orders/OrdersAdd.vue"),
        },
        //销售订单修改
        {
          path: "/ordersUpdate",
          name: "ordersUpdate",
          component: () => import("../views/Orders/ordersUpdate.vue"),
        },
        //入库单列表
        {
          path: "/StorageShow",
          name: "StorageShow",
          component: () => import("../views/Warehousing/StorageShow.vue"),
        },
        //入库单添加
        {
          path: "/StorageAdds",
          name: "StorageAdds",
          component: () => import("../views/Warehousing/StorageAdds.vue"),
        },
        //入库单修改
        {
          path: "/StorageUpdates",
          name: "StorageUpdates",
          component: () => import("../views/Warehousing/StorageUpdates.vue"),
        },
        //入库单修改
        {
          path: "/StorageReport",
          name: "StorageReport",
          component: () => import("../views/Warehousing/StorageReport.vue"),
        },
        {
          //物料需求计划显示
          path: "/MaterialPlanning/MaterialPlanningList",
          name: "MaterialPlanningList",
          component: () =>
            import("../views/MaterialPlanning/MaterialPlanningList.vue"),
        },
        {
          //物料需求计划添加
          path: "/MaterialPlanning/MaterialPlanningAdd",
          name: "MaterialPlanningAdd",
          component: () =>
            import("../views/MaterialPlanning/MaterialPlanningAdd.vue"),
        },
        {
          //物料需求计划修改
          path: "/MaterialPlanning/MaterialPlanningUpdate",
          name: "MaterialPlanningUpdate",
          component: () =>
            import("../views/MaterialPlanning/MaterialPlanningUpdate.vue"),
        },
        {
          //生产任务显示
          path: "/ProductionTasks/ProductionTasksList",
          name: "ProductionTasksList",
          component: () =>
            import("../views/ProductionTasks/ProductionTasksList.vue"),
        },
        {
          //生产任务添加
          path: "/ProductionTasks/ProductionTasksAdd",
          name: "ProductionTasksAdd",
          component: () =>
            import("../views/ProductionTasks/ProductionTasksAdd.vue"),
        },
        {
          //生产任务修改
          path: "/ProductionTasks/ProductionTasksMang",
          name: "ProductionTasksMang",
          component: () =>
            import("../views/ProductionTasks/ProductionTasksMang.vue"),
        },
        // {
        //   //物料需求计划修改
        //   path: '/MaterialPlanning/MaterialPlanningUpdate',
        //   name: 'MaterialPlanningUpdate',
        //   component: () => import('../views/MaterialPlanning/MaterialPlanningUpdate.vue'),
        // },
        {
          //供应商管理添加
          path: "/ProducManagement/SuppliersAdd",
          name: "SuppliersAdd",
          component: () =>
            import("../views/ProducManagement/SuppliersAddView.vue"),
        },
        {
          //供应商显示
          path: "/ProducManagement/SuppliersQuery",
          name: "SuppliersQuery",
          component: () =>
            import("../views/ProducManagement/SuppliersQueryView.vue"),
        },
        {
          //供应商修改
          path: "/ProducManagement/SuppliersEdit",
          name: "SuppliersEdit",
          component: () =>
            import("../views/ProducManagement/SuppliersEditView .vue"),
        },
        {
          //工作中心的显示列表页面
          path: "/WorkCenters/WorkCenterShowHtml",
          name: "WorkCenterShowHtml",
          component: () =>
            import("../views/WorkCenters/WorkCenterShowHtml.vue"),
        },
        {
          //工作中心的新增页面
          path: "/WorkCenters/WorkCenterAddHtml",
          name: "WorkCenterAddHtml",
          component: () => import("../views/WorkCenters/WorkCenterAddHtml.vue"),
        },
        {
          //采购/委外订单添加
          path: "/ProducManagement/PurchasingsAdd",
          name: "PurchasingsAdd",
          component: () =>
            import("../views/ProducManagement/PurchasingsAddView.vue"),
        },
        {
          //采购/委外订单显示
          path: "/ProducManagement/PurchasingsQuery",
          name: "PurchasingsQuery",
          component: () =>
            import("../views/ProducManagement/PurchasingsQueryView.vue"),
        },
        {
          //采购/委外订单修改
          path: "/ProducManagement/PurchasingsEdit",
          name: "PurchasingsEdit",
          component: () =>
            import("../views/ProducManagement/PurchasingsEditView .vue"),
        },
        {
          //采购/委外订单修改
          path: "/WorkCenters/WorMHtml",
          name: "WorMHtml",
          component: () => import("../views/WorkCenters/WorMHtml.vue"),
        },
        {
          //工单看板
          path: "/ProducManagement/WorkOrderBoard",
          name: "WorkOrderBoard",
          component: () =>
            import("../views/ProducManagement/WorkOrderBoardView.vue"),
        },
      ],
    },
  ],
});
// 全局前置守卫
router.beforeEach((to, from, next) => {
  const isAuthenticated = !!localStorage.getItem("userInfo"); // 假设认证令牌存储在 localStorage 中

  if (
    to.matched.some((record) => record.meta.requiresAuth) &&
    !isAuthenticated
  ) {
    next({ name: "Login" }); // 如果需要认证但用户未认证，则重定向到登录页面
  } else {
    next(); // 确保一定要调用 next()
  }
});

export default router;
